﻿using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CADTool.Jig
{
    public class UseDrawJig
    {
        public class ElRecJig : DrawJig
        {
            public Ellipse m_Ellipse;  //椭圆
            private Autodesk.AutoCAD.DatabaseServices.Polyline m_Polyline;
            private Point3d m_Pt1;
            //派生类的构造函数
            public ElRecJig(Point3d pt1,Ellipse ellipse, Autodesk.AutoCAD.DatabaseServices.Polyline polyline)
            {
                //仅传递参数
                m_Pt1= pt1; //矩形的第一个角点（UCS坐标）
                m_Ellipse= ellipse;
                m_Polyline= polyline;
            }
            protected override SamplerStatus Sampler(JigPrompts prompts)
            {
                Editor ed=Application.DocumentManager.MdiActiveDocument.Editor;
                Matrix3d mt = ed.CurrentUserCoordinateSystem;
                //定义一个点拖拽交互类
                JigPromptPointOptions optjigPoint= new JigPromptPointOptions("\n请指定矩形的另一点：");
                //光标类型
                optjigPoint.Cursor = CursorType.Crosshair;
                //拖拽限制
                optjigPoint.UserInputControls = UserInputControls.Accept3dCoordinates | UserInputControls.NoZeroResponseAccepted |
                    UserInputControls.NoNegativeResponseAccepted;
                //拖拽点必须是WCS点
                optjigPoint.BasePoint = m_Pt1.TransformBy(mt);
                optjigPoint.UseBasePoint= true;
                //用AcquirePoint函数获得拖拽的即时点
                PromptPointResult resJigPoint=prompts.AcquirePoint(optjigPoint);
                if (resJigPoint.Status==PromptStatus.Cancel)
                {
                    return SamplerStatus.Cancel;
                }
                //拖拽
                return SamplerStatus.Cancel;
            }
            protected override bool WorldDraw(WorldDraw draw)
            {
                draw.Geometry.Draw(m_Ellipse);
                draw.Geometry.Draw(m_Polyline);
                return true;
            }
        }
    }
}
